
#ifndef CONSOLELOGGER_H_
#define CONSOLELOGGER_H_

#include <cstdio>
#include <ctime>
#include <iostream>
#include <mutex>

#include "Logger/Logger.h"
#include "Logger/LogStringFormatter.h"

namespace logger {

/**
 * A very simple @c Logger that logs to console.
 */
class ConsoleLogger
        : public Logger
        , private std::ios_base::Init {
public:
    /**
     * Return the one and only @c ConsoleLogger instance.
     *
     * @return The one and only @c ConsoleLogger instance.
     */
    static std::shared_ptr<Logger> instance();

    void emit(Level level, std::chrono::system_clock::time_point time, const char* text) override;

private:
    /**
     * Constructor.
     */
    ConsoleLogger();

    /// Mutex to serialize writing to cout.
    std::shared_ptr<std::mutex> m_coutMutex;

    /// Object to format log strings correctly.
    LogStringFormatter m_logFormatter;
};

/**
 * Return the singleton instance of @c ConsoleLogger.
 *
 * @return The singleton instance of @c ConsoleLogger.
 */
std::shared_ptr<Logger> getConsoleLogger();

}  // namespace logger

#endif  // CONSOLELOGGER_H_
